<template>
  <div class="login-container">
    <el-card class="login-card" shadow="hover">
      <div slot="header" class="clearfix">
        <span>请先登录</span>
      </div>
      <el-form @submit.native.prevent="login">
        <el-form-item label="用户名">
          <el-input
            v-model="model.username"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            type="password"
            v-model="model.password"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      model: {}
    }
  },
  methods: {
    async login () {
      const res = await this.$http.post('login', this.model)
      // 浏览器支持本地存储时，将token存到localStorage中
      if (typeof (window.Storage) !== 'undefined') {
        localStorage.token = res.data.token
        this.$message({
          type: 'success',
          message: '登陆成功'
        })
        this.$router.push('/')
      } else {
        console.log('浏览器不支持web存储')
      }
      console.log(res)
    }
  }
}
</script>

<style>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
.el-card {
  width: 30rem;
  /* background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); */
}

.el-input .el-input__inner {
  /* background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); */
  color: #000;
}

.el-input__inner::-webkit-input-placeholder {
  /* WebKit browsers */
  color: #606266 !important;
}
</style>
